package com.example.train.business.controller;

import com.example.train.common.context.LoginMemberContext;
import com.example.train.common.resp.CommonResp;
import com.example.train.common.resp.PageResp;
import com.example.train.business.req.Train_CarriageQueryReq;
import com.example.train.business.req.Train_CarriageSaveReq;
import com.example.train.business.resp.Train_CarriageQueryResp;
import com.example.train.business.service.Train_CarriageService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/train_Carriage")

public class Train_CarriageController {

    @Resource
    private Train_CarriageService train_CarriageService;

    /**
     * 乘客注册请求的controller类，用于调用service
     * 注意PostMapping必须要用requestBody注解，否则后端接受不到数据
     * @param train_CarriageSaveReq
     * @return
     */
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody Train_CarriageSaveReq train_CarriageSaveReq) {
        train_CarriageService.save(train_CarriageSaveReq);
        return new CommonResp<>();
    }
    /**
     * 查询当前会员下乘客信息列表的controller类，用于调用service
     * 注意GetMapping不用requestBody注解，否则后端接受不到数据
     * @param @VALID Train_CarriageQueryReq
     * @return CommonResp<PageResp<Train_CarriageQueryResp>>
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<Train_CarriageQueryResp>> queryList(@Valid Train_CarriageQueryReq req) {
        PageResp<Train_CarriageQueryResp> list = train_CarriageService.queryList(req);
        return new CommonResp<>(list);
    }

    /**
     * 删除乘客信息的controller层接口
     * @param id
     * @return CommonResp<Object>
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        train_CarriageService.delete(id);
        return new CommonResp<>();
    }

}

